﻿<%@ Page Title="info" Language="C#" MasterPageFile="~/EasyUI.master" AutoEventWireup="true" CodeBehind="myList.aspx.cs" Inherits="jnagr.Web.info.myList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 
    <script type="text/javascript">
        var myzu = "";
        Date.prototype.pattern = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1, //月份        
                "d+": this.getDate(), //日        
                "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时        
                "H+": this.getHours(), //小时        
                "m+": this.getMinutes(), //分        
                "s+": this.getSeconds(), //秒        
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度        
                "S": this.getMilliseconds() //毫秒        
            };
            var week = {
                "0": "/u65e5",
                "1": "/u4e00",
                "2": "/u4e8c",
                "3": "/u4e09",
                "4": "/u56db",
                "5": "/u4e94",
                "6": "/u516d"
            };
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            }
            if (/(E+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
            }
            for (var k in o) {
                if (new RegExp("(" + k + ")").test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                }
            }
            return fmt;
        }
        var Common = {

            //EasyUI用DataGrid用日期格式化
            TimeFormatter: function (value, rec, index) {
                if (value == undefined) {
                    return "";
                }
                /*json格式时间转js时间格式*/
                value = value.substr(1, value.length - 2);
                var obj = eval('(' + "{Date: new " + value + "}" + ')');
                var dateValue = obj["Date"];
                if (dateValue.getFullYear() < 1900) {
                    return "";
                }
                var val = dateValue.pattern("yyyy-MM-dd HH:mm");
                return val;
            },
            DateTimeFormatter: function (value, rec, index) {

                if (value == null || value == '') {
                    return '';
                }
                var dt;
                if (value instanceof Date) {
                    dt = value;
                }
                else {
                    dt = new Date(value);
                    if (isNaN(dt)) {
                        value = value.replace(/\/Date\((-?\d+)\)\//, '$1'); //标红的这段是关键代码，将那个长字符串的日期值转换成正常的JS日期格式
                        dt = new Date();
                        dt.setTime(value);
                    }
                }
                return dt.pattern("yyyy年M月d日");
            },

            //EasyUI用DataGrid用日期格式化
            DateFormatter: function (value, rec, index) {
                if (value == undefined) {
                    return "";
                }
                /*json格式时间转js时间格式*/
                value = value.substr(1, value.length - 2);
                var obj = eval('(' + "{Date: new " + value + "}" + ')');
                var dateValue = obj["Date"];
                if (dateValue.getFullYear() < 1900) {
                    return "";
                }

                return dateValue.pattern("yyyy-MM-dd");
            }
        };        
        $(function () {
            var result = $.ajax({
                url: "../admin/getinfo.ashx?action=myzu",
                type: 'post',
                dataType: 'json',
                async: false,
                cache: false
            }).responseText;
            //$("#psinfo").html(result);
            myzu=result;
            InitGird();

        });
        //初始化表格
        function InitGird() {
            $('#tt').datagrid({
                title: '信息列表('+myzu+")", //表格标题
                url: 'GetInfo.ashx', //请求数据的页面
                sortName: 'infotime', //排序字段
                idField: 'iid', //标识字段,主键
                iconCls: '', //标题左边的图标
                //width: '100%', //宽度
                height: '100%',// $(parent.document).find("#mainPanle").height() - 50 > 0 ? $(parent.document).find("#mainPanle").height() - 80 : 500, //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                method: 'post',
                columns: [[                    
	                { title: '标题', field: 'title', width: 150, sortable: true },
                    {
                        title: '发布时间', field: 'infotime', width: 150, sortable: true, formatter: function (value, row, index) {
                            if (value != "") {
                                if (value.indexOf("-") != -1)
                                    value = value.replace(/-/g, "/");
                                return new Date(value).pattern("yyyy年M月d日");
                            }                            
                        }
                    },
                    { title: '发布人', field: 'uname', width: 150 },
                    {
                        title: '状态', field: 'isread', width: 150, sortable: true, formatter: function (value, row, index) {
                            if(value=='0')
                                return '<span style="color:red">未读</span>';
                            else
                                return '已读';
                        }
                    },
                    {
                        title: '操作', field: 'iid', width: 80, formatter: function (value, row, index) {

                            return '<a style="color:red" href="javascript:" onclick="$(this).parent().click();showData(' + value + ');return false;">详细信息</a>';
                        }
                    }
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "querymy" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号
            });


        }       
        function getQueryParams(queryParams) {
            var StartTime = $("#StartTime").datetimebox("getValue");
            var EndTime = $("#EndTime").datetimebox("getValue");
            var uname = $("#uname").val();
            var title = $("#title").val();
            queryParams.StartTime = StartTime;
            queryParams.EndTime = EndTime;
            queryParams.uname = uname;
            queryParams.title = title;
            return queryParams;
        }
        //增加查询参数，重新加载表格  
        function reloadgrid() {
            //查询参数直接添加在queryParams中      
            var queryParams = $('#tt').datagrid('options').queryParams;
            getQueryParams(queryParams);
            $('#tt').datagrid('options').queryParams = queryParams;
            $("#tt").datagrid('reload');
        }
        function showData(value) {
            //清空内容            
            //$('#dlg').dialog('open').dialog('setTitle', '信息');
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要显示的行！", "info");
            }
            if (row) {
                $('#dlg').dialog('open').dialog('setTitle', '详细信息');
                $("#caname").text(row.caname);                
                $("#stitle").text(row.title);
                $("#suname").text(row.uname);
                var result = $.ajax({
                    url: "GetInfo.ashx?action=getinfo&iid=" + row.iid,
                    type: 'post',
                    dataType: 'json',
                    async: false,
                    cache: false
                }).responseText;                
                $('#infocontent').html(result);
            }
        }
      
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="tt">
    </table>
    
    <div id="tab_toolbar" style="padding: 4px;">
        <table cellpadding="0" cellspacing="0" style="width: 100%">
            <tr>

                <td style="padding-left: 2px">
                    <div>  
           时间从:  
           <input id="StartTime" class ="easyui-datetimebox" style="width: 150px" />  
           到:  
           <input id="EndTime" class="easyui-datetimebox" style="width: 150px" />   
          标题:   
           <input id="title" class="easyui-validatebox"/>   
           作者：  
             <input id="uname" class="easyui-validatebox"/> 
           <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reloadgrid()">查找</a>  
       </div>                   
                </td>
            </tr>
        </table>
    </div>  
     <div id="dlg" class="easyui-dialog" style="width: 850px; height: auto; padding: 10px 20px"
        data-options="closed:true,buttons:'#dlg-buttons',shadow:false,top:50">
        <form id="fm" method="post" >
            <div class="fitem">
                <label>群组名：</label>
                <span id="caname"  />
                </div>
            <div class="fitem">
                <label>标题：</label>
                <span id="stitle"  />
            </div> 
            <div class="fitem">
                <label>作者：</label>
                <span id="suname" />
            </div>           
            <div >
                <label>内容：</label>
                
                <span  id="infocontent"  ></span>               
                <input name="iid" id="iid" type="hidden" />                   
                <input id="key" name="key" onkeydown="if(event.keyCode==13)reloadgrid()" type="hidden" />                
            </div>
            <div>                         
                </div>
        </form>
    </div>
    <div id="dlg-buttons">        
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close');reloadgrid();">关闭</a>
    </div>
   
</asp:Content>
